<?php
/*
*微信扫码支付
*开发文档：https://pay.weixin.qq.com/wiki/doc/api/native?chapter=6_3
*步骤：在公众号设置处获取AppID和AppSecret，在微信商家后台api安全设置api秘钥（key）
*/
include "../control/ku/configure.php";
/*********微信扫码支付**************************************************/
//需要引入的参数
$money = $_POST['money'] * 100;//本次付款的金额，单位为分
$orderType = $_POST['type'];//订单类型
$orderIdGroup = $_POST['orderIdGroup'];//支付对象的ID号
if(empty($money)){
	$json['warn'] = "付款金额不能为空";
}elseif(preg_match($CheckInteger,$money) == 0){
	$json['warn'] = "付款金额格式有误";
}elseif(empty($orderType)){
	$json['warn'] = "订单类型不能为空";
}elseif(empty($orderIdGroup)){
	$json['warn'] = "支付对象ID号不能为空";
}else{
	//赋值
	$wx['appid'] = website("sz3d4fgew8");//公众账号应用ID
	$wx['mch_id'] = website("alisdf2546h");//商户号
	$wx['nonce_str'] = suiji();//随机字符串
	$wx['body'] = website("sfd3g4sd8e");//商品描述
	$wx['out_trade_no'] = rand(100,999).time().rand(100,999);//商户订单号
	$wx['total_fee'] = $money;
	$wx['spbill_create_ip'] = $_SERVER['REMOTE_ADDR'];//终端IP
	$wx['notify_url'] = root."pay/wxpay/wxpayReturn.php";//通知地址
	$wx['trade_type'] = "NATIVE";//交易类型
	$wx['sign'] = wxsign($wx);
	//生成xml
	$xml = arrayToXml($wx);
	//生成预支付交易
	$url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
	$pay = xmlToArray(Curl($url,$xml));
	//在系统中保存预支付记录
	mysql_query(" insert into pay (id,type,target,targetId,orderType,orderIdGroup,money,workFlow,updateTime,time) 
	values ('$wx[out_trade_no]','微信扫码支付','客户','$kehu[khid]','$orderType','$orderIdGroup','$money','未支付','$time','$time') ");
	//根据返回的url生成二维码
	$json['url'] = $pay['code_url'];
	$json['warn'] = 2;
}
/*********返回json数据**************************************************/
echo json_encode($json);
?>